package com.gimi.cloud.jimi.client.controller.userInfo;

import com.gimi.cloud.jimi.client.service.userInfo.EmergencyContactService;
import com.gimi.cloud.jimi.common.enums.ResponseCodeEnum;
import com.gimi.cloud.jimi.common.utils.JsonUtil;
import com.gimi.cloud.jimi.common.utils.reqhead.Response;
import com.gimi.cloud.jimi.common.utils.reqhead.Util;
import com.gimi.cloud.jimi.dto.userInfo.RdEmergencyContactDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping(value = "userEmergency")
public class EmergencyContactController {

    @Autowired
    private EmergencyContactService emergencyContactService;

    @RequestMapping("/save")
    public void saveEmergencyContact(@RequestBody RdEmergencyContactDTO param, HttpServletResponse response) {
        Response resp = new Response();
        emergencyContactService.saveEmergencyContact(param);
        resp.setResponseCode(ResponseCodeEnum.SUCCESSED);
        Util.sendResponse(JsonUtil.toJson(resp), response);
    }

    @RequestMapping("/getByUser")
    public void getEmergencyContact(@RequestBody RdEmergencyContactDTO param, HttpServletResponse response) {
        Response resp = new Response();
        RdEmergencyContactDTO dto = emergencyContactService.findEmergencyContactByUser(param);
        resp.setRes_data(dto);
        resp.setResponseCode(ResponseCodeEnum.SUCCESSED);
        Util.sendResponse(JsonUtil.toJson(resp), response);
    }

}
